<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY copy "&#169;">
  <!ENTITY nbsp "&#160;">
  <!ENTITY laquo "&#171;">
  <!ENTITY raquo "&#187;">
]>
<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:include href="layout.xsl"/>

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template name="Head-List">
    <div class="contenthead">
      <xsl:call-template name="Create_Path">
        <xsl:with-param name="without_last" select="1"/>
      </xsl:call-template>
      <div class="top">
        <span class="title">
          <xsl:value-of select="$Cats/row[id=$Content/@cat]/title" />
        </span>
        <xsl:choose>
          <xsl:when test="$Cat = 980">
            
          </xsl:when>
          <xsl:otherwise>
            <span class="actions">
              <input name="button_add" id="button_add" value="Додати" type="button" />
              <!--  <input name="button_remove" id="button_remove" value="- Удалить" type="button"/>-->
            </span>
          </xsl:otherwise>
        </xsl:choose>
      </div>
    </div>


    <div class="sort">
      <span>З виділеними:</span>
      
      <a href="javascript:;" id="button_remove">видалити</a>
    </div>
  </xsl:template>

  <xsl:template match="List">
    <link rel="stylesheet" type="text/css" href="/css/ArtPager.css" />
    <script type="text/javascript" src="/js/list_actions.js"></script>
    <script type="text/javascript" src="/js/listing.js"></script>

    <form id="list_form" name="list_form" action="" method="post">
      <input type="hidden" id="controller" value="{$Controller}"/>
      <input type="hidden" id="table_name" value="{$Main/List/head/@table_name}"/>
      <table width="100%" border="0" cellpadding="0" cellspacing="0" class="widefat">

        <thead>
          <tr class="header" bgColor="#EFEFEF">
            <td width="10" class="action">
              <a href="?sort=norder&amp;dr=0">#</a>
            </td>
            <xsl:if test="$Main/List/params/checkboxes = 1">
              <td width="5%" class="action" >
                <input id="check_all" type="checkbox"/>
              </td>
            </xsl:if>

            <xsl:for-each select="head/row">
              <td>
                <xsl:if test="@width">
                  <xsl:attribute name="width">
                    <xsl:value-of select="@width"/>
                  </xsl:attribute>
                </xsl:if>

                <xsl:if test="sort_field_name = /page/content/Main/List/head/@sort">
                  <xsl:if test="@sort = 1">
                    <xsl:if test="/page/content/Main/List/head/@dr = 0">
                      <img src="{$Images}/arrow_down.gif" width="14" height="6" />
                    </xsl:if>
                    <xsl:if test="/page/content/Main/List/head/@dr = 1">
                      <img src="{$Images}/arrow_up.gif" width="14" height="6" />
                    </xsl:if>
                  </xsl:if>
                </xsl:if>

                <xsl:choose>
                  <xsl:when test="@sort = 1">
                    <xsl:choose>
                      <xsl:when test="sort_field_name = /page/content/Main/List/head/@sort">
                        <xsl:choose>
                          <xsl:when test="/page/content/Main/List/head/@dr = 0">
                            <A href="{$This}?sort={sort_field_name}&amp;dr=1">
                              <xsl:value-of select="title"/>
                            </A>
                          </xsl:when>
                          <xsl:otherwise>
                            <A href="{$This}?sort={sort_field_name}&amp;dr=0">
                              <xsl:value-of select="title"/>
                            </A>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:when>
                      <xsl:otherwise>
                        <A href="{$This}?sort={sort_field_name}&amp;dr=0">
                          <xsl:value-of select="title"/>
                        </A>
                      </xsl:otherwise>
                    </xsl:choose>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="title"/>
                  </xsl:otherwise>
                </xsl:choose>
              </td>
            </xsl:for-each>


            <xsl:for-each select="$Main/List/func/row">
              <td>
                <xsl:choose>
                  <xsl:when test="type = 'order'">
                    <a href="/{$Controller}/reorder/id/{$Form/id_cat/row[@active]/id}">
                      <xsl:value-of select="title"/>
                    </a>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="title"/>
                  </xsl:otherwise>
                </xsl:choose>
                
              </td>
            </xsl:for-each>

          </tr>
        </thead>
        <tbody>
          <xsl:if test="count(data/data/row) = 0">
            <tr>
              <td colspan="{$Main/List/head/@count + $Main/List/func/@count}" align="center">
                Нет записей
              </td>
            </tr>
          </xsl:if>

          <xsl:for-each select="data/data/row">
            <xsl:variable name="id" select="id" />
            <xsl:variable name="file_name" select="file_name" />
            <xsl:variable name="path" select="path" />

            <tr class="data-row">
              <td>
                <xsl:value-of select="position()"/>
              </td>
              <xsl:if test="$Main/List/params/checkboxes = 1">
                <td>
                  <input type="checkbox" value="{$id}" name="selected_id[]" class="checkboxlist"/>
                </td>
              </xsl:if>

              <!-- Data List -->
              <xsl:for-each select="node()[@type = 'field']">
                <xsl:choose>
                  <!-- AVATAR -->
                  <xsl:when test="name(.)='path'">
                    <td class="cur">
                      <xsl:choose>
                        <xsl:when test="$Main/List/params/link">
                          <a href="{$Main/List/params/link}/{$id}">
                            <xsl:choose>
                              <xsl:when test="current() != ''">
                                <img src="{$Files}{current()}{$id}square_small{$file_name}" width="50" border="0"/>
                              </xsl:when>
                              <xsl:otherwise>
                                <img src="{$Images}/user50.jpg" width="50" border="0"/>
                              </xsl:otherwise>
                            </xsl:choose>
                          </a>
                        </xsl:when>
                        <xsl:otherwise>
                          <a href="/{$Controller}/{$id}">
                            <xsl:choose>
                              <xsl:when test="current() != ''">
                                <img src="{$Files}{current()}{$id}square_small{$file_name}" width="50" border="0"/>
                              </xsl:when>
                              <xsl:otherwise>
                                <img src="{$Images}/user50.jpg" width="50" border="0"/>
                              </xsl:otherwise>
                            </xsl:choose>
                          </a>
                        </xsl:otherwise>
                      </xsl:choose>
                    </td>
                  </xsl:when>

                  <!-- DATE -->
                  <xsl:when test="./row/@day">
                    <td class="cur">

                      <xsl:call-template name="Write.Date">
                        <xsl:with-param name="node" select="current()/row"/>
                      </xsl:call-template>
                    </td>
                  </xsl:when>

                  <!-- LINK FIELD -->
                  <xsl:when test="name(.)=$Main/List/params/link_fields">
                    <td class="cur">
                      <xsl:choose>
                        <xsl:when test="$Main/List/params/link">
                          <a href="{$Main/List/params/link}/{$id}">
                            <xsl:value-of select="current()"/>
                          </a>
                        </xsl:when>
                        <xsl:otherwise>
                          <a href="/{$Controller}/{$id}">
                            <xsl:value-of select="current()"/>
                          </a>
                        </xsl:otherwise>
                      </xsl:choose>
                    </td>
                  </xsl:when>

                  <!-- default LINK FIELD -->
                  <xsl:when test="(name(.)='name' or name(.)='title' or name(.)='title_ru' or name(.)='name_ru' or name(.)='name_full' or name(.)='username') and not($Main/List/params/link_fields)">
                    <td class="cur">
                      <a href="/{$Controller}/{$id}">
                        <xsl:value-of select="current()" disable-output-escaping="yes"/>
                      </a>
                    </td>
                  </xsl:when>

                  <xsl:otherwise>
                    <td class="cur">
                      <xsl:value-of select="current()" disable-output-escaping="yes"/>
                    </td>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:for-each>

              <!-- Function List -->
              <xsl:for-each select="node()[@type = 'func']">
                <td align="center">
                  <xsl:choose>
                    <!-- Checkbox -->
                    <xsl:when test="./type = 'checkbox'">
                      <a href="javascript:;" onclick="return list_func_checkbox({$id}, '{./field}');">
                        <input type="hidden" value="{./value}" rel="{./field}{$id}"/>
                        <div class="loader{./field}{$id}" style="display:none;">
                          <img src="{$Images}/loader.gif" alt="Выполняется..." title="Выполняется..."/>
                        </div>
                        <div class="func{./field}{$id}">
                          <xsl:choose>
                            <xsl:when test="./value = 1">
                              <div class="on" rel="{./field}{$id}" value="0">
                                <img src="{$Images}/{./img/on}" alt="{./alt}" title="{./alt}"/>
                              </div>
                              <div style="display:none;" class="off" rel="{./field}{$id}" value="1">
                                <img src="{$Images}/{./img/off}" alt="{./alt_off}" title="{./alt_off}" />
                              </div>
                            </xsl:when>
                            <xsl:otherwise>
                              <div style="display:none;" class="on" rel="{./field}{$id}" value="0">
                                <img src="{$Images}/{./img/on}" alt="{./alt}" title="{./alt}"/>
                              </div>
                              <div class="off" rel="{./field}{$id}" value="1">
                                <img src="{$Images}/{./img/off}" alt="{./alt_off}" title="{./alt_off}" />
                              </div>
                            </xsl:otherwise>
                          </xsl:choose>
                        </div>
                      </a>
                    </xsl:when>

                    <!-- ORDER -->
                    <xsl:when test="./type = 'order'">
                      <div style="width: 100px;">
                        <xsl:choose>
                          <xsl:when test="$Action = 'index'">
                            <input type="text" name="norder" value="{./value}" rel="{$id}" size="4" old="{./value}" cat="{$Form/id_cat/row[@active=1]/id}" style="text-align: center;"/>    
                          </xsl:when>
                          <xsl:otherwise>
                            <input type="text" name="norder" value="{./value}" rel="{$id}" size="4" old="{./value}" cat="{$Main/@id}" style="text-align: center;"/>
                          </xsl:otherwise>
                        </xsl:choose>
                        
                        
                        <input type="hidden" id="ajax-order-url" value="/{$Controller}/ajax-order/">
                          <xsl:if test="./ajax">
                            <xsl:attribute name="value">
                              <xsl:value-of select="./ajax"/>
                            </xsl:attribute>
                          </xsl:if>
                        </input>
                        <a style="float:left;" href="/{$Controller}/order/id/{$id}/d/1">
                          <xsl:if test="./url">
                            <xsl:attribute name="href">
                              <xsl:value-of select="./url"/>/id/<xsl:value-of select="$id"/>/d/1
                            </xsl:attribute>
                          </xsl:if>
                          <img src="{$Images}/{./img/up}" alt="Поднять" title="Поднять"/>
                        </a>
                        <a style="float:left;" href="/{$Controller}/order/id/{$id}/d/2">
                          <xsl:if test="./url">
                            <xsl:attribute name="href">
                              <xsl:value-of select="./url"/>/id/<xsl:value-of select="$id"/>/d/2
                            </xsl:attribute>
                          </xsl:if>
                          <img src="{$Images}/{./img/down}" alt="Опустить" title="Опустить" />
                        </a>
                        
                      </div>
                    </xsl:when>
                  </xsl:choose>
                </td>
              </xsl:for-each>
            </tr>
          </xsl:for-each>
        </tbody>

      </table>

      <xsl:if test="$Main/List/data/pager/end_page > 1">
        <div class="pages">
          <xsl:call-template name="pager1">
            <xsl:with-param name="node" select="/page/content/Main/List/data/pager"></xsl:with-param>
          </xsl:call-template>
          <input name="pager_submit" type="submit" value="Показывать:" />
          <select name="pager_count" >
            <xsl:for-each select="/page/content/Main/List/pager_count_list/row">
              <option value="{current()}">
                <xsl:if test="/page/content/Main/List/pager_count_list/@active = current()">
                  <xsl:attribute name="selected">
                    selected
                  </xsl:attribute>
                </xsl:if>
                <xsl:value-of select="current()"/>
              </option>
            </xsl:for-each>
          </select>

        </div>
      </xsl:if>
    </form>
  </xsl:template>


  <xsl:template name="pager1">
    <xsl:param name="node"></xsl:param>

    <xsl:variable name="sort" select="/page/content/main/@sort" />
    <xsl:variable name="family" select="/page/content/main/@family" />
    <xsl:variable name="fromTopic" select="/page/content/main/@fromTopic" />

    <!-- page left -->
    <div class="fclr"></div>

    <xsl:if test="number($node/page_count) &gt; 1">

      <div class="ArtPager">
        <span class="innerText">
          Показано з
          <xsl:value-of select="number($node/start_item)" />
          по
          <xsl:value-of select="$node/end_item" />
          із
          <xsl:value-of select="$node/items_count" />

        </span>


        <div class="pageLeft"></div>
        <a href="#" class="pageCenter">
          <xsl:choose>
            <xsl:when test="number($node/current_page) &gt; 1">
              <xsl:attribute name="href">
                <xsl:text>?page=</xsl:text>
                <xsl:value-of select="number($node/current_page) - 1"/>

                <xsl:if test="string-length($sort) &gt; 0">
                  <xsl:text>&amp;sort=</xsl:text>
                  <xsl:value-of select="$sort"/>
                </xsl:if>

                <xsl:if test="string-length($family) &gt; 0">
                  <xsl:text>&amp;family=</xsl:text>
                  <xsl:value-of select="$family"/>
                </xsl:if>

                <xsl:if test="string-length($fromTopic) &gt; 0">
                  <xsl:text>&amp;fromTopic=</xsl:text>
                  <xsl:value-of select="$fromTopic"/>
                </xsl:if>


              </xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
              <xsl:attribute name="style">
                cursor:default;
              </xsl:attribute>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:text> </xsl:text>
          <img src="{$Images}/pagerleft.gif" alt="" border="0" style="position:relative; top:4px;" />
        </a>
        <div class="pageRight"></div>



        <xsl:call-template name="pager1.counter">
          <xsl:with-param name="i" select="$node/start_page"></xsl:with-param>
          <xsl:with-param name="node" select="$node"></xsl:with-param>
        </xsl:call-template>


        <span class="innerText2"> із </span>

        <div class="pageLeft"></div>
        <a href="?page={$node/last_page}" class="pageCenter">

          <xsl:if test="string-length($sort) &gt; 0">
            <xsl:attribute name="href">
              <xsl:text>?page=</xsl:text>
              <xsl:value-of select="$node/last_page"/>
              <xsl:text>&amp;sort=</xsl:text>
              <xsl:value-of select="$sort"/>
            </xsl:attribute>
          </xsl:if>

          <xsl:if test="string-length($family) &gt; 0">
            <xsl:attribute name="href">
              <xsl:text>?page=</xsl:text>
              <xsl:value-of select="$node/last_page"/>
              <xsl:text>&amp;family=</xsl:text>
              <xsl:value-of select="$family"/>
            </xsl:attribute>
          </xsl:if>


          <xsl:if test="string-length($fromTopic) &gt; 0">
            <xsl:attribute name="href">
              <xsl:text>?page=</xsl:text>
              <xsl:value-of select="$node/last_page"/>
              <xsl:text>&amp;fromTopic=</xsl:text>
              <xsl:value-of select="$fromTopic"/>
            </xsl:attribute>
          </xsl:if>


          <xsl:value-of select="$node/last_page"/>
        </a>
        <div class="pageRight"></div>

        <div class="pageLeft"></div>
        <a href="#" class="pageCenter">
          <xsl:choose>
            <xsl:when test="number($node/current_page) &lt; number($node/last_page)">
              <xsl:attribute name="href">
                <xsl:text>?page=</xsl:text>
                <xsl:value-of select="number($node/current_page) + 1"/>


                <xsl:if test="string-length($sort) &gt; 0">
                  <xsl:text>&amp;sort=</xsl:text>
                  <xsl:value-of select="$sort"/>
                </xsl:if>

                <xsl:if test="string-length($family) &gt; 0">
                  <xsl:text>&amp;family=</xsl:text>
                  <xsl:value-of select="$family"/>
                </xsl:if>


                <xsl:if test="string-length($fromTopic) &gt; 0">
                  <xsl:text>&amp;fromTopic=</xsl:text>
                  <xsl:value-of select="$fromTopic"/>
                </xsl:if>

              </xsl:attribute>
            </xsl:when>
          </xsl:choose>
          <img src="{$Images}/pagerright.gif" alt="" border="0" style="position:relative; top:4px;"/>
          <xsl:text> </xsl:text>
        </a>
        <div class="pageRight"></div>

        <div class="fclr"></div>
      </div>
      <!-- pager right -->
    </xsl:if>
  </xsl:template>

  <xsl:template name="pager1.counter">
    <xsl:param name="i"></xsl:param>
    <xsl:param name="node"></xsl:param>

    <xsl:variable name="sort" select="/page/content/main/@sort" />
    <xsl:variable name="family" select="/page/content/main/@family" />
    <xsl:variable name="fromTopic" select="/page/content/main/@fromTopic" />

    <xsl:choose>
      <xsl:when test="number($node/current_page) = number($i)">
        <div class="pageLeftActive"></div>
        <a  href="#" class="pageCenterActive" style="cursor:default;">
          <xsl:value-of select="$i"/>
        </a>
        <div class="pageRightActive"></div>
      </xsl:when>
      <xsl:otherwise>
        <!-- show -> -->
        <div class="pageLeft"></div>
        <a href="?page={$i}" class="pageCenter">

          <xsl:if test="string-length($sort) &gt; 0">
            <xsl:attribute name="href">
              <xsl:text>?page=</xsl:text>
              <xsl:value-of select="$i"/>
              <xsl:text>&amp;sort=</xsl:text>
              <xsl:value-of select="$sort"/>
            </xsl:attribute>
          </xsl:if>

          <xsl:if test="(string-length($family) &gt; 0) or (string-length($fromTopic) &gt; 0)">
            <xsl:attribute name="href">
              <xsl:text>?page=</xsl:text>
              <xsl:value-of select="$i"/>
              <xsl:text>&amp;family=</xsl:text>
              <xsl:value-of select="$family"/>
              <xsl:text>&amp;fromTopic=</xsl:text>
              <xsl:value-of select="$fromTopic"/>
            </xsl:attribute>
          </xsl:if>


          <!--xsl:if test="string-length($fromTopic) &gt; 0">
            <xsl:attribute name="href">
              <xsl:text>?page=</xsl:text>
              <xsl:value-of select="$i"/>
              <xsl:text>&amp;fromTopic=</xsl:text>
              <xsl:value-of select="$fromTopic"/>
            </xsl:attribute>
          </xsl:if -->


          <xsl:value-of select="$i"/>
        </a>
        <div class="pageRight"></div>
      </xsl:otherwise>
    </xsl:choose>


    <!-- test -> -->

    <xsl:if test="(number($i) &lt; (number($node/start_page)+4)) and number($i) &lt; (number($node/last_page)) ">
      <xsl:call-template name="pager1.counter">
        <xsl:with-param name="i" select="$i+1"></xsl:with-param>
        <xsl:with-param name="node" select="$node"></xsl:with-param>
      </xsl:call-template>
    </xsl:if>

  </xsl:template>

</xsl:stylesheet>